<?php
//--FETCH/INSERT
function insertGallery($contName, $offset)
{
	//checker
	$tables = array();
	$tables[0] = 'site_content';
	
	$fields = array();
	$fields[0] = 'contentID';
	
	$whereClause = 'conttype="gallery" AND contName="'.$contName.'"';
	
	$data = SQLRecover($tables, $fields, $whereClause);
	
	$returnVal = ($data['queryStatus'] == 'DB Query success!' ? true : false);
	
	if($returnVal)
	{
		//display existing values
		/*
		DATA GUIDE:
		title - File name of jpg including Title of description. replace _ with space.
		contName - category - similar to get('cat');
		contdata - description only. - does not include title. - placed in the 'ext' or 'title' tag.
			NOTE: EDIT LIGHTBOX!!!!
		*/
		$tables = array();
		$tables[0] = 'site_content';
		
		$fields = array();
		$fields[0] = 'title pName';
		$fields[1] = 'contdata pDesc';
		$fields[2] = 'contentID id';
		$fields[3] = 'dateUpdated date';
		
		$whereClause = 'contName = "'.$contName.'" AND conttype="gallery" ORDER BY title ASC';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		$output = '';
		
		$logCheck = secureLogIn();
		
		if ($logCheck == '1')
		{
			$data['pName'][sizeOf($data['pName'])] = 'Add_New_Product';
		}

		$limit = ($offset+12 > sizeOf($data['pName']) ? sizeOf($data['pName']) : $offset+12);
		
		for ($i=$offset; $i<$limit; $i++)
		{
			
			if($i == sizeOf($data['pName']) -1 && $logCheck == '1')
			{
				$output .= '<div class="prodBox"><a href="widget.php?page=gallery&subcat='.get('cat').'" title="Add New Product" rel="cms"><div id="gallbox">
		<div style="width: 195px; margin: auto; text-align: left; font-size: 9pt;">
		<img src="img/products/thumb/_dummy/'.$data['pName'][$i].'.jpg" />
		'.str_replace("_", " ", $data['pName'][$i]).'
		</div>
	</div></a></div>';
			}
			else
			{
				$lBEnable = adminContent('rel="admin" alt="'.$data['id'][$i].'"','rel="lightbox"');
				$adminL = adminContent('<div id="'.$data['id'][$i].'" class="slider adminSlide">Item#'.$data['id'][$i].' | <a href="widget.php?page=gallery&id='.$data['id'][$i].'&subcat='.get('cat').'" rel="cms">Edit</a> <a href="#" rel="'.INDEX.'cat'.EXT.'ajax=delete&id='.$data['id'][$i].'&cat='.get('cat').'&offset=0" title="Delete">Delete</a></div>', '');
				
				$output .= '<div class="prodBox"><a href="img/products/full/'.$contName.'/'.$data['pName'][$i].'.jpg" '.$lBEnable.' name="<div class=\'descTitle\'>'.str_replace("_", " ", $data['pName'][$i]).'</div><div class=\'descProper\'>'.$data['pDesc'][$i].'</div>"><div id="gallbox">
					<div style="width: 195px; margin: auto; text-align: left; font-size: 9pt;">
					<img src="img/products/thumb/'.$contName.'/'.$data['pName'][$i].'.jpg" />
					'.str_replace("_", " ", $data['pName'][$i]).'
					</div>
				</div></a>'.$adminL.'</div>';
				
			}
		}
		
		return $output;
	}
	else
	{
		//create new value
		$tableName = 'site_content';
		
		$fields = array();
		$fields[0] = 'title';
		$fields[1] = 'contName';
		$fields[2] = 'contdata';
		$fields[3] = 'conttype';
		$fields[4] = 'perPage';
		$fields[5] = 'dateUpdated';

		$values = array();
		$values[0] = 'Default';
		$values[1] = $contName;
		$values[2] = 'No Description';
		$values[3] = 'gallery';
		$values[4] = '0';
		$values[5] = sqlDateNow();
 		
		$data = SQLInsert($tableName, $fields, $values);
		
		return 'Gallery Element Created. Reload page to display content.'; 
	}
}

function getCategory($getvar)
{
	$tables = array();
	$tables[0] = 'site_content';
	
	$fields = array();
	$fields[0] = 'contdata';
	
	$whereClause = 'contName = "'.$getvar.'" AND conttype="category"';
	
	$data = SQLRecover($tables, $fields, $whereClause);
	
	if (!isset($data['contdata']) || sizeOf($data['contdata'][0]) <= 0)
	{
		$data['contdata'][0] = 'Category Not Found';
	}	
	return str_replace("_", " ", $data['contdata'][0]);
}
//--PAGINATION FUNCTIONS
function getPagination($category)
{
	$tables = array();
	$tables[0] = 'site_content';
	
	$fields = array();
	$fields[0] = 'contentID';
	
	$whereClause = 'conttype="gallery" AND contName = "'.$category.'"';
	
	$data = SQLRecover($tables, $fields, $whereClause);
	if (!isset($data['contentID']) || 1>sizeOf($data['contentID']))
	{
		$output = '';
	}
	else
	{
		$output = ceil(sizeOf($data['contentID']) / 12);
	}
/* 	echo $output.'<br />'; */
	return $output;
}
//--CATEGORY FUNCTIONS
function categories($testVariable, $func)
{
	$category = array();
	$category[0][0] = 'Beds';
	$category[0][1] = 'Bunk';
	$category[0][2] = 'Double';
	$category[0][3] = 'Folding';
	$category[0][4] = 'Other';
	$category[0][5] = 'Single';
	$category[1][0] = 'Decoratives';
	$category[1][1] = 'Candles';
	$category[1][2] = 'Curtain_Rods';
	$category[1][3] = 'Flowers';
	$category[1][4] = 'Painting';
	$category[1][5] = 'Vases';
	$category[1][6] = 'Wooden_Balls';
	$category[1][7] = 'Figurines';
	$category[1][8] = "Picture_Frames";
	$category[2][0] = 'Foam';
	$category[2][1] = 'Foam';
	$category[3][0] = 'Lighting';
	$category[3][1] = 'Hanging';
	$category[3][2] = 'Outdoor';
	$category[3][3] = 'Standing';
	$category[3][4] = 'Table_Lamp';
	$category[3][5] = 'Wall';
	$category[4][0] = 'Seating';
	$category[4][1] = 'Bench';
	$category[4][2] = 'Dining_Chairs';
	$category[4][3] = 'Lounge_Chairs';
	$category[4][4] = 'Ottoman';
	$category[4][5] = 'Recliners';
	$category[5][0] = 'Sofa';
	$category[5][1] = 'Two_Seater';
	$category[5][2] = 'Three_Seater';
	$category[5][3] = 'L_Sofa';
	$category[5][4] = 'Set';
	$category[5][5] = 'Sofa-Beds';
	$category[5][6] = 'Wooden';
	$category[6][0] = 'Storage';
	$category[6][1] = 'Bookcase';
	$category[6][2] = 'Cabinets';
	$category[6][3] = 'CD_Racks';
	$category[6][4] = 'Drawer';
	$category[6][5] = 'TV_Rack';
	$category[6][6] = 'Wardrobe';
	$category[7][0] = 'Tables';
	$category[7][1] = 'Center_Table';
	$category[7][2] = 'Coffee_Table';
	$category[7][3] = 'Console_Table';
	$category[7][4] = 'Dining';
	$category[7][5] = 'Dresser_Table';
	$category[7][6] = 'Side_Table';
	$category[8][0] = 'Mattress';
	$category[8][1] = 'Base';
	$category[8][2] = 'Top';
	$category[9][0] = 'Pillows';
	$category[9][1] = 'Pillows';
	$category[10][0] = 'Others';
	$category[10][1] = 'Children';
	$category[10][2] = 'Office_Desk';
	$category[10][3] = 'Outdoor_Set';
	$category[10][4] = 'Office_Chair';
	$category[11][0] = 'null';
	if ($func == 'check')
	{
		$signal = false;
		for ($i=0; $i<sizeOf($category); $i++)
		{
			for ($j=0; $j<sizeOf($category[$i]); $j++)
			{
				if ($testVariable == $category[$i][$j])
				{
					$signal = true;
				}
			}	
		}
	}
	else
	{
		$signal = false;
	}
	
	return $signal;
}

/*
function setCategories($activate)
{
	if($activate)
	{
		//CREATES CATEGORIES. ONLY USED WHEN DB IS EMPTY.
		$category = array();
		$category[0][0] = 'Beds';
		$category[0][1] = 'Bunk';
		$category[0][2] = 'Double';
		$category[0][3] = 'Folding';
		$category[0][4] = 'Other';
		$category[0][5] = 'Single';
		$category[1][0] = 'Decoratives';
		$category[1][1] = 'Candles';
		$category[1][2] = 'Curtain_Rods';
		$category[1][3] = 'Flowers';
		$category[1][4] = 'Painting';
		$category[1][5] = 'Vases';
		$category[1][6] = 'Wooden Balls';
		$category[2][0] = 'Foam';
		$category[2][1] = 'Foam';
		$category[3][0] = 'Lighting';
		$category[3][1] = 'Hanging';
		$category[3][2] = 'Outdoor';
		$category[3][3] = 'Standing';
		$category[3][4] = 'Table Lamp';
		$category[3][5] = 'Wall';
		$category[4][0] = 'Seating';
		$category[4][1] = 'Bench';
		$category[4][2] = 'Dining_Chairs';
		$category[4][3] = 'Lounge_Chairs';
		$category[4][4] = 'Ottoman';
		$category[4][5] = 'Recliners';
		$category[5][0] = 'Sofa';
		$category[5][1] = '2_Seater';
		$category[5][2] = '3_Seater';
		$category[5][3] = 'L_Sofa';
		$category[5][4] = 'Set';
		$category[5][5] = 'Sofa-Beds';
		$category[5][6] = 'Wooden';
		$category[6][0] = 'Storage';
		$category[6][1] = 'Bookcase';
		$category[6][2] = 'Cabinets';
		$category[6][3] = 'CD_Racks';
		$category[6][4] = 'Drawer';
		$category[6][5] = 'TV Rack';
		$category[6][6] = 'Wardrobe';
		$category[7][0] = 'Tables';
		$category[7][1] = 'Center_Table';
		$category[7][2] = 'Coffee_Table';
		$category[7][3] = 'Console_Table';
		$category[7][4] = 'Dining';
		$category[7][5] = 'Dresser_Table';
		$category[7][6] = 'Side_Table';
		$category[8][0] = 'Mattress';
		$category[8][1] = 'Base';
		$category[8][2] = 'Top';
		$category[9][0] = 'Pillows';
		$category[9][1] = 'Pillows';
		$category[10][0] = 'Others';
		$category[10][1] = 'Children';
		$category[10][2] = 'Office_Desk';
		$category[10][3] = 'Outdoor_Set';
		$category[10][4] = 'Office_Chair';
	
		$tableName = 'site_content';
		$fields = array();
		$fields[0] = 'title';
		$fields[1] = 'contName';
		$fields[2] = 'contdata';
		$fields[3] = 'conttype';
		$fields[4] = 'perPage';
		$fields[5] = 'dateUpdated';
	
		$queryCount = 0;
		$indexCount = 0;
		for ($i=0; $i<sizeOf($category); $i++)
		{
			for ($j=1; $j<sizeOf($category[$i]); $j++)
			{
				$values = array();
				$values[0] = $category[$i][0];
				$values[1] = $category[$i][$j];
				$values[2] = $category[$i][0].' > '.$category[$i][$j];
				$values[3] = 'category';
				$values[4] = '0';
				$values[5] = sqlDateNow();
				$data = SQLInsert($tableName, $fields, $values);
				
				$queryCount = ($j == 0 ? $queryCount = $queryCount : $queryCount + 1);
			}
			$indexCount++;
		}
		$true = 'Catergory Query Report: '.$indexCount.' Indices, '.$queryCount.' Queries.';
		return $true;
	}
	else
	{
		//doNothing();
		return 'false';
	}
}
*/
?>